// pages/searchOrderList/searchOrderList.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pages: 0,
    account: '',
    customerOrderList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      pages: 0,
      orderList: [],
      account: options.account || ''
    })
  },

  // 获取搜索的腾讯云订单列表
  getTencentCloudOrderList: function() {
    var that = this;
    this.data.pages++;
    var data = {
      point_url: app.server.agentApi.getTencentCloudOrderList,
      page_no: this.data.pages,
      page_size: 10,
      owner_uin: this.data.account
    };
    app.server.getConnect(data).then(function(res) {
      that.setData({
        customerOrderList: that.data.customerOrderList.concat(res.data.list || [])
      })
      if (res.data.list.length === 0) {
        app.showConfirm('提示', '无相关订单', false, function () {
          wx.navigateBack()
        });
      }
    })
  },

  // 跳转订单详情
  toOrderDetails: function(e) {
    var id = e.currentTarget.dataset.id||'';
    wx.navigateTo({
      url: '/pages/agent/plugins/tencentCloud/orderDetails/orderDetails?id='+id,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    app.pageOnloadInit(this, app);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.setData({
      customerOrderList: []
    })
    this.getTencentCloudOrderList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.getTencentCloudOrderList();
    app.pageOnloadInit(this, app);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.getTencentCloudOrderList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})
